/*
	Programação Concorrente
	Trabalho 2
	Turma A

	Adilson Abreu Couto Rapozo Junior ( n. USP: 6402336 )
	Luiz Alfredo Bertoni ( n. USP: 6418834 )
	Rodrigo Fernandes da Costa ( n. USP: 6793073 )
*/

#include "main.h"

int isPrime ( char * pWord ) {
	int max_sum;
	int *prime;
	int result;
	int sum_ascii = 0;
	int i, j;

	for ( i = 0; pWord[i] != '\0'; ++i ){
		sum_ascii += (int) pWord[i];
	}

	max_sum = i*'z';/* value of the highest possible ASCII*/	

	printf ( "primeSize = %d\n" , max_sum ) ;	
	prime = ( int * ) malloc( max_sum * sizeof(int) );	
	
	prime[0] = prime [1] = 0;
	prime[2] = 1;
	
	for( i=3; i<= sum_ascii; ++i ){
		prime[i] = i%2;
	}
	
	#pragma omp parallel num_threads(2)
	{	
		
		for( i=3; i*i<=sum_ascii; i+=2)
			if( prime[i] )
				for( j=i*i; j<= sum_ascii; j+=i)
					prime[j] = 0;
	}/* omp end parallel*/
	result = prime[sum_ascii];
	free( prime );
 
	return result;
}



